#pragma once


//#include "BBox3f.hpp"

#include "vertex_formats.h"
#include <glm/glm.hpp>

#include <vector>
#include <map>
#include <string>

class Shader;
//class GameManager;


struct GeomData
{
	//GeomData();
	std::vector< XYZ > vertices;
	std::vector< XYZ > normals;
	std::vector< UV > texCoords;
	std::vector< XYZ > colors;
	std::vector<unsigned int> indices;

#ifdef _BBOX
	GMlib::Box<float,3> boundingBox;
	std::vector<Vector3D> boundingBoxVerts;
	bool drawBoundingBox;
#endif

	// todo, destructor for vao,vbo,ibo gl_handles
	//glDeleteBuffers(1, &ibo);
	//glDeleteBuffers(1, &vbo);
	//glDeleteVertexArrays(1, &vao);

	unsigned int vao;
	unsigned int vbo;
	unsigned int ibo;
	unsigned int vaoBBox;
	unsigned int vboBBox;
	Shader* shader;
	unsigned int primitiveMode; // GL_QUADS, GL_TRIANGLES, GL_LINES

	//void render(GameManager* gm);
	void render();
	void renderDepth();
	//void render(GameManager* gm, unsigned int texture);
	std::string name;
};

class GeometryManager
{
public:
	static GeometryManager* Instance();
	static void init();
	static void destroy();
	static GeomData* getGeomData(std::string type);
	static void CreateTriangleMesh(std::string meshName, std::vector<XYZ>& vertices, std::vector<XYZ>& normals);
	static void CreateTriangleMesh(std::string meshName, unsigned int primitiveMode, std::vector<XYZ>& vertices, std::vector<XYZ>& normals, std::vector<unsigned int>& indices);

private:
	static GeometryManager* _instance;
	static std::map<std::string, GeomData*> geomData;

	static void createBox(std::vector<XYZ>& vertices, std::vector<UV>& tex, std::vector<XYZ>& normals, float width, float height, float breadth);	
	static void initVAO(GeomData* data);
	#ifdef _BBOX
	static void initBBoxVao(GeomData* data);
	#endif
	
};